package com.spark.sniffer.plugin.plugins.interceptor;

import net.bytebuddy.asm.Advice;

import java.lang.reflect.Method;

import static net.bytebuddy.implementation.bytecode.assign.Assigner.Typing.DYNAMIC;

/**
 * Description: 请描述你的文件
 *
 * @author wuqirong
 * @date 2021-08-02
 * <p>
 * All rights Reserved, Designed www.xiao100.com
 */
public class ObjectStaticMethodInterceptor {

    /**
     *  当advice方法的返回值是
     *  {false for boolean , 0 for byte、short、char、int、long、float 、double 或者null for 引用类型 }
     *  那么就跳过目标方法。方法则不执行，如果有返回值则返回null
     */
    @Advice.OnMethodEnter(skipOn = Advice.OnDefaultValue.class)
    public static boolean before(
        @Advice.AllArguments Object[] allArguments,
        @Advice.Origin Method method) {
        System.out.println("ObjectStaticMethodInterceptor");
        System.out.println(allArguments);
        System.out.println(method);
        return true;
    }

    @Advice.OnMethodExit(onThrowable = Throwable.class)
    public static void after(@Advice.AllArguments Object[] allArguments,
        @Advice.Origin Method method, @Advice.Return(readOnly = false, typing = DYNAMIC) Object returnValue,
        @Advice.Thrown Throwable thrown) {
        System.out.println(allArguments);
        System.out.println(method);
        System.out.println(returnValue);
        System.out.println(thrown);
//        returnValue = 7;
    }

}
